<html>
    <head>
    <title>JavaScript RSSClient Sample</title>
    <script src="../rssclient.js" type="text/javascript"></script>
    <script type="text/javascript">
    	
		// create an instance of RSSClient
		var client = new RSSClient();
		
		// make sure the RSSClient is loaded
		client.onload(function() {
			
			// url of rss feed
			var url = 'http://rss.news.yahoo.com/rss/topstories';
			
			// retrieve the rss feed
			client.getRSS(url, function(xml) {
				
				// retrieve the channel and title of the RSS feed
				var channel = xml.getElementsByTagName('channel')[0];
				var channel_title = channel.getElementsByTagName('title')[0].firstChild.nodeValue;
				
				// add the RSS title to the page
				document.getElementById('title').innerHTML = channel_title;
				
				// retrieve the items
				var items = channel.getElementsByTagName('item');
				
				for (var i = 0; i < items.length; i++) {
				
					// retrieve title, link, desc from the item
					var title = items[i].getElementsByTagName('title')[0].firstChild.nodeValue;
					var link = items[i].getElementsByTagName('link')[0].firstChild.nodeValue;
					var description = items[i].getElementsByTagName('description')[0].firstChild.nodeValue;
					
					// add the item to the page
					var h2 = document.createElement('h2');
					var a = document.createElement('a');
					a.setAttribute('href', link);
					a.setAttribute('target', '_blank');
					h2.appendChild(a);
					a.innerHTML = title;
					document.getElementById('items').appendChild(h2);
					var p = document.createElement('p');
					p.innerHTML = description;
					document.getElementById('items').appendChild(p);
					
				}
				
			})
		});
		
    </script>
</head>
<body>
	
	<h1 id="title"></h1>
	<div id="items">
		
	</div>
	
</body>
</html>